package servlet.echarts;

import bean.vo.*;
import commons.baseServlet.BaseServlet;
import commons.r.R;
import service.EchartsService;
import service.impl.EchartsServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;
import java.util.Vector;

/**
 * servlet
 * User: 邱
 * Date: 2024/12/16 16:12
 * Description:
 * Version: V1.0
 */
@WebServlet("/echarts/*")
public class EchartsServlet extends BaseServlet {
    EchartsService echartsService = new EchartsServiceImpl();

    /**
     * 查询缴费情况
     * @param request
     * @return
     */
    public R findChargeList(HttpServletRequest request){
        MonthDataVo monthDataVo = echartsService.findChargeList();

        return R.ok().addData("zeroMonthData", monthDataVo.getZeroMonthData())
                .addData("oneMonthData", monthDataVo.getOneMonthData())
                .addData("xAxis", monthDataVo.getXAxis())
                .addData("title", new String[]{"已缴费", "未缴费"});
    }

    /**
     * 查询访客情况
     * @param request
     * @return
     */
    public R findVisitorList(HttpServletRequest request){
        MonthDataVo monthDataVo = echartsService.findVisitorList();

        return R.ok().addData("zeroMonthData", new Vector<>().add(0))
                .addData("oneMonthData", monthDataVo.getOneMonthData())
                .addData("xAxis", monthDataVo.getXAxis())
                .addData("title", new String[]{"访客数", ""});
    }

    /**
     * 查询投诉情况
     * @param request
     * @return
     */
    public R findComplaintList(HttpServletRequest request){
        MonthDataVo monthDataVo = echartsService.findComplaintList();

        return R.ok().addData("zeroMonthData", new Vector<>().add(0))
                .addData("oneMonthData", monthDataVo.getOneMonthData())
                .addData("xAxis", monthDataVo.getXAxis())
                .addData("title", new String[]{"投诉数", ""});
    }

    /**
     * 查询售卖情况
     * @param request
     * @return
     */
    public R findSaleGoodsList(HttpServletRequest request){
        MonthDataVo monthDataVo = echartsService.findSaleGoodsList();

        return R.ok().addData("zeroMonthData", new Vector<>().add(0))
                .addData("oneMonthData", monthDataVo.getOneMonthData())
                .addData("xAxis", monthDataVo.getXAxis())
                .addData("title", new String[]{"售卖数", ""});
    }

    /**
     * 查询医疗预约情况
     * @param request
     * @return
     */
    public R findMedicalList(HttpServletRequest request){
        Map<String, List> list = echartsService.findMedicalList();

        return list != null ? R.ok(list) : R.ok("没有医疗预约情况数据");
    }

    /**
     * 查询费用类型及其对应费用
     * @param request
     * @return
     */
    public R findChargeRecord(HttpServletRequest request){
        Map<String, List> map = echartsService.findChargeRecord();

        return R.ok(map);
    }

    /**
     * 查询维修项目及其对应次数
     * @param request
     * @return
     */
    public R findMaintenance(HttpServletRequest request){
        Map<String, List> map = echartsService.findMaintenance();

        return R.ok(map);
    }

    /**
     * 查询访客人数
     * @param request
     * @return
     */
    public R findVisitorNumber(HttpServletRequest request){
        VisitorNumVo visitorNumVo = echartsService.findVisitorNumber();

        return R.ok(visitorNumVo);
    }

    /**
     * 查询总已缴费金额和未缴费金额
     * @param request
     * @return
     */
    public R findPayment(HttpServletRequest request){
        PaymentVo payment = echartsService.findPayment();

        return R.ok(payment);
    }

    /**
     * 查询业主和居民人数
     * @param request
     * @return
     */
    public R findAllOwner(HttpServletRequest request){
        // 业主人数
        DwellerNumVo ownerNumVo = echartsService.findAllOwner();
        // 居民人数
        DwellerNumVo dwellerNumVo = echartsService.findAllDweller();

        return R.ok().addData("ownerNum", ownerNumVo.getOwnerNum()).addData("dwellerNum", dwellerNumVo.getDwellerNum());
    }

    /**
     * 查询售卖商品数
     * @param request
     * @return
     */
    public R findSaleGoodsNum(HttpServletRequest request){
        OrderInfoVo orderInfoVo = echartsService.findSaleGoodsNum();

        return R.ok().addData("saleGoodsNum", orderInfoVo.getSaleGoodsNum());
    }

    /**
     * 查询投诉数
     * @param request
     * @return
     */
    public R findComplaintNum(HttpServletRequest request){
        DwellerNumVo complaintNumVo = echartsService.findComplaintNum();

        return R.ok().addData("complaintNum", complaintNumVo.getComplaintNum());
    }
}
